home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / mg / rexx / rot13.mg < prev    next >
Text File  |  1995-03-09  |  794b  |  38 lines

  1. /* Rot13 a Mg-region */
  2.  
  3. options results
  4.  
  5. 'rexx-region' fooey
  6. 'kill-region'
  7.  
  8. do i=1 to fooey.0
  9.     if index(fooey.i,'0d'x) then text=slashquote(rot13(left(fooey.i,length(fooey.i)-1)))||'\n'
  10.     else text=slashquote(rot13(fooey.i))
  11.     'rexx-insert "'||text||'"'
  12.     end
  13. exit
  14.  
  15. rot13: procedure
  16. parse arg foo
  17. foo = translate(foo,'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM','abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  18. return foo
  19.  
  20. /* slashquote - puts '\' in front of any '"''s or '\''s we find in a string */
  21. slashquote: procedure
  22. parse arg in
  23.  
  24. i = index(in, '\')
  25. do while i > 0
  26.     in = substr(in, 1, i - 1)'\\'substr(in, i + 1)
  27.     i = index(in, '\', i + 2)
  28.     end
  29.  
  30. i = index(in, '"')
  31. do while i > 0
  32.     in = substr(in, 1, i - 1)'\"'substr(in, i + 1)
  33.     i = index(in, '"', i + 2)
  34.     end
  35.  
  36. return in
  37.  
  38.